package com.java.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.java.model.*;
import com.java.service.*;
import com.java.utils.CommonUtils;
import com.java.utils.JsonBody;
import com.java.utils.ResponseUtil;
import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;;

@RestController
public class IndexController {
	@Autowired
	private ThingTypeService thingtypeService;
	@Autowired
	private ThingType2Service thingtype2Service;
	@Autowired
	private ThingService thingService;

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;



	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("index")
	public JsonBody  index() {
		Pages p=new Pages();
		p.setPagesize(6);
		Thing t=new Thing();
		t.setPage(p);

		List<ThingType> tt=thingtypeService.Get();
		List<ThingType2> tt2=thingtype2Service.Get();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("thingtype", tt);
		map.put("thingtype2",tt2);

		for(ThingType t1:tt)
		{
			t.setThingtypeId(t1.getId());
			map.put("tt1"+t1.getId().toString(), thingService.Get(t));
		}

		for(ThingType2 t2:tt2)
		{
			t.setThingtypeId(null);
			t.setThingtype2Id(t2.getId());
			map.put("tt2"+t2.getId().toString(), thingService.Get(t));
		}
		return Util.SetData(map);

	}

	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("config")
	public JsonBody  config() {
		List<ThingType> tt=thingtypeService.Get();
		List<ThingType2> tt2=thingtype2Service.Get();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("thingtype", tt);
		map.put("thingtype2",tt2);
		return Util.SetData(map);

	}
}
